#include <iostream>
#include <string.h>

typedef char* string;

string createString(const string str)
{
int len=0;
while(str[len++]);
string s=new char[len];
strcpy(s,str);
return s;
}
class Stack
{
	public:
		Stack(int capability):_capability(capability),_top(0)
		{
		this->_innerList = new string[capability];
		
		}
		~Stack()
		{
			if(this->_innerList){
				clear();
				delete [] this->_innerList;
			}
		}
	private:
		string * _innerList;
		int _capability;
		int _top;
	public:
		void push(const string item){
			if(this->_top >= this->_capability)
			{
			this->resize();
			}
			this->_innerList[_top++]=item;

		}
		const string pop() {
		if(_top >0){
			return this->_innerList[--_top];
			}
			return NULL;
		}
		void clear()
		{
			for(int i=0; i< _top; i++)
			{
			delete[] _innerList[i];
			
			}
		_top=0;
		}
		int resize()
		{
			 
		int newCapability=_capability*2;
		string * temp=new string[newCapability];
		for(int i=0;i<_capability;i++)
		{
		temp[i]=_innerList[i];
		}
		_capability= newCapability;
		delete[] _innerList;
		_innerList=temp;
		return  newCapability;		
		}
};
class WebNavigation
{
	string currentLink;
	public:
		WebNavigation():BackStack(100), ForwardStack(100)
		{
		this->currentLink=NULL;
		}
		~WebNavigation()
		{}
	public:
		void Enter(const string url)
		{
			if(this->currentLink!=NULL)
			BackStack.push(this->currentLink);
			this->currentLink=createString(url);
			ForwardStack.clear();
		}
		string Back(){
		string s=BackStack.pop();
		if(s){
		if(this->currentLink!=NULL)
		{
			ForwardStack.push(this->currentLink);
		}
		
		this->currentLink = s;
		}
		return s;
		}
		string Forward(){
			string s=ForwardStack.pop();
			if(s){
			if(this->currentLink!=NULL)
			{
				BackStack.push(this->currentLink);
			}
			
			this->currentLink = s;
			}
			return s;
		}
	private:
		Stack BackStack;
		Stack ForwardStack;
	

};
char gs[128]; 

int main()
{
WebNavigation wn;
char cmd[32];
string s;
wn.Enter("http://www.acm.org/");
while(1)
{
	std::cin>>cmd;
	if(strcmp(cmd,"QUIT")==0) break;
	if(strcmp(cmd,"VISIT")==0)
	{
		
		std::cin>>gs;
		wn.Enter(gs);
		std::cout<<gs<<"\n";
	}
	else if(strcmp(cmd,"BACK")==0)
	{
		s=wn.Back();
		std::cout<<(s?s:"Ignored")<<std::endl;
	
	}
	else if(strcmp(cmd,"FORWARD")==0)
	{
		s=wn.Forward();
		std::cout<<(s?s:"Ignored")<<std::endl;
	}
}
return 0;
}
